﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>GuiFromHwnd - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The GuiFromHwnd function retrieves the Gui object of a GUI window associated with the specified HWND." />
<meta name="ahk:equiv-v1" content="commands/Gui.htm" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css">
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>GuiFromHwnd</h1>

<p>Retrieves the <a href="../objects/Gui.htm">Gui object</a> of a GUI window associated with the specified HWND.</p>
<pre class="Syntax">GuiObj := <span class="func">GuiFromHwnd</span>(Hwnd <span class="optional">, RecurseParent := false</span>)</pre>

<h2 id="Parameters">参数</h2>
<dl>
  <dt>Hwnd</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>The window handle (HWND) of a GUI window. Such window could be created with <a href="GuiCreate.htm">GuiCreate</a>.</p>
  </dd>
  <dt>RecurseParent</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#boolean">整数(布尔值)</a></p>
    <p>If this parameter is 1 (true), the closest parent to the specified HWND that is a GUI is automatically searched for and retrieved.</p>
  </dd>
</dl>
  
<h2 id="Labels">Return Value</h2>
<p>类型: <a href="../Concepts.htm#objects">对象</a></p>
<p>This function returns a <a href="../Concepts.htm#references-to-objects">reference</a> to an existing <a href="../objects/Gui.htm">Gui object</a>. This object provides methods and properties for creating and managing windows, and creating controls. </p>

<h2 id="Remarks">备注</h2>
<p>例如, a HWND of a GUI window can be retrieved via <a href="../objects/Gui.htm#Hwnd">Gui.Hwnd</a>, <a href="WinExist.htm">WinExist</a> or <a href="WinGetID.htm">WinGetID</a>.</p>

<h2 id="Related">相关</h2>
<p><a href="GuiCreate.htm">GuiCreate</a>, <a href="../objects/Gui.htm">Gui object</a>, <a href="../objects/GuiControl.htm">GuiControl object</a>, <a href="GuiCtrlFromHwnd.htm">GuiCtrFromHwnd</a>, <a href="GuiControls.htm">Control Types</a>, <a href="ListView.htm">ListView</a>, <a href="TreeView.htm">TreeView</a>, <a href="../objects/Menu.htm">Menu object</a>, <a href="Control.htm">Control functions</a>, <a href="MsgBox.htm">MsgBox</a>, <a href="FileSelect.htm">FileSelect</a>, <a href="DirSelect.htm">DirSelect</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>Gui := GuiCreate(, "Title of Window")
Gui.Add("Text",, "Some text to display.")
Gui.Show()

MsgBox(GuiFromHwnd(Gui.Hwnd).Title)</pre>
</div>

</body>
</html>